﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;
using System.Threading;
using System.Globalization;

using mfXmlSerializer;
using mfXmlSerializer.TestObjects;

namespace mfXmlSerializer.Test
{
    [TestClass]
    public class ExtensionTest
    {
        [TestMethod]
        public void Extension_IsCustomClass_System_DateTime()
        {
            bool res = typeof(DateTime).IsCustomClass();

            Assert.AreEqual(false, res);
        }

        [TestMethod]
        public void Extension_IsCustomClass_Custom_Parameter()
        {
            bool res = typeof(Parameter).IsCustomClass();

            Assert.AreEqual(true, res);
        }

        private static DateTime refDateTime()
        {
            var exp = new DateTime(2014, 1, 12, 13, 12, 59);
            return exp;
        }



        [TestMethod]
        public void Extension_ConvertToDateTime_ValidString_ISO8601_WithoutTimeOffset()
        {
            TestSetUps.SetupDateTimeTests();

            var cur = "2014-01-12T13:12:59".ConvertToDateTime();
            var exp = refDateTime();

            Assert.AreEqual(exp, cur);
        }

        [TestMethod]
        public void Extension_ConvertToDateTime_ValidString_ISO8601_WithPositiveTimeOffset()
        {
            TestSetUps.SetupDateTimeTests();
            //YYYY-MM-ddTHH:mm:ss+HH:mm
            var cur = "2014-01-12T13:12:59+01:00".ConvertToDateTime();
            var exp = refDateTime();

            Assert.AreEqual(exp, cur);
        }

        [TestMethod]
        public void Extension_ConvertToDateTime_ValidString_ISO8601_WithNegativeTimeOffset()
        {
            TestSetUps.SetupDateTimeTests();

            var cur = "2014-01-12T13:12:59-01:00".ConvertToDateTime();
            var exp = refDateTime();

            Assert.AreEqual(exp, cur);
        }

        [TestMethod]
        [ExpectedException(typeof(mfXmlException))]
        public void Extension_ConvertToDateTime_Invalid_Month()
        {
            TestSetUps.SetupDateTimeTests();

            var cur = "2014-32-12T13:12:59+01:00".ConvertToDateTime();
            var exp = refDateTime();

            Assert.AreEqual(exp, cur);
        }

        [TestMethod]
        [ExpectedException(typeof(mfXmlException))]
        public void Extension_ConvertToDateTime_Invalid_Day()
        {
            TestSetUps.SetupDateTimeTests();

            var cur = "2014-01-35T13:12:59+01:00".ConvertToDateTime();
            var exp = refDateTime();

            Assert.AreEqual(exp, cur);
        }

        [TestMethod]
        [ExpectedException(typeof(mfXmlException))]
        public void Extension_ConvertToDateTime_Invalid_asdf_AsString()
        {
            TestSetUps.SetupDateTimeTests();

            var cur = "asdf".ConvertToDateTime();
            var exp = refDateTime();

            Assert.AreNotEqual(exp, cur);
        }

        [TestMethod]
        public void Extension_SerializeBoolAsString_Valid_True()
        {
            var cur = true.SerializeAsString();

            Assert.AreEqual("True", cur);
        }
        [TestMethod]
        public void Extension_SerializeBoolAsString_Valid_False()
        {
            var cur = false.SerializeAsString();

            Assert.AreEqual("False", cur);
        }
        [TestMethod]
        public void Extension_DeserializeBool_Valid_True()
        {
            var cur = "True".DeserializeBool();

            Assert.AreEqual(true, cur);
        }
        [TestMethod]
        public void Extension_DeserializeBool_Valid_False()
        {
            var cur = "False".DeserializeBool();

            Assert.AreEqual(false, cur);
        }
        [TestMethod]
        [ExpectedException(typeof(mfXmlException))]
        public void Extension_DeserializeBool_Invalid_asdf()
        {
            "asdf".DeserializeBool();

        }
    }
}
